package com.cssw.fyzb.web.service;

import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.core.dao.msg.MsgDao;
import com.cssw.fyzb.core.model.dodb.SysMessage;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Auther: zzf
 * @Date: 2020/12/4 14:47
 * @Description:
 */
@Service
public class SystemMsgService {

    @Autowired
    private MsgDao msgDao;

    public AjaxPage list(int page, int limit, Map param) {
        Page<SysMessage> list = msgDao.listMsg(page, limit, param);
        return AjaxPage.success(list.getList(), list.getTotalRow(), list.getTotalPage());
    }

    public AjaxData detail(Long msgId) {
        return AjaxData.success(msgDao.detail(msgId));
    }

    public AjaxData save(String title, String content, Long operId) {
        List<SysMessage> list = msgDao.listTitle(title);
        if (list.size() > 0) {
            return AjaxData.failure("标题重复");
        }
        msgDao.save(title, content, operId);
        return AjaxData.success();
    }

    public AjaxData update(Long msgId, String title, String content, Long operId) {
        msgDao.update(msgId, title, content, operId);
        return AjaxData.success();
    }

    public AjaxData delete(Long msgId, Long operId) {
        msgDao.updateStatus(msgId,SysMessage.STATUS_INVALID, operId);
        return AjaxData.success();
    }
}
